package net.xin.servlet.imple;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import net.xin.dao.UserDAO;
import net.xin.model.User;
import net.xin.servlet.UserServlet;

@Component(value="servlet")	/*相当于在xml中初始化对象*/
@Scope(value="singleton")
public class UserServletImple implements UserServlet {
	
	UserDAO dao;	/*由applicationContext.xml初始化,提高灵活性【控制反转】*/
	
	
	public UserDAO getDao() {
		return dao;
	}

	@Resource(name="sqlDAO")	/*选择调用哪种保存的方式，注入,改保存方式，改这里即可*/
	public void setDao(UserDAO dao) {
		this.dao = dao;
	}


	@Override
	public void add(User user) {
		// TODO Auto-generated method stub
		dao.save(user);
	}

	@Override
	public boolean checkExists(User user) {
		// TODO Auto-generated method stub
		return dao.isExists(user);
	}

	@Override
	public User get(User user) {
		// TODO Auto-generated method stub
		return dao.get(user);
	}

}
